home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Code Resources / Progress CDEF 1.3.2 / Progress.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-18  |  3.4 KB  |  156 lines  |  [TEXT/CWIE]

  1. /* ----------------------------------------------------------------------
  2.  
  3.     Progress CDEF
  4.     version 1.3.2
  5.     
  6.     Written by: Paul Celestin
  7.     
  8.     Copyright © 1993-1997 Celestin Company, Inc.
  9.     
  10.     This CDEF displays a very simple progress thermometer.
  11.     
  12.     930927 - 1.0.0 - initial release
  13.     931012 - 1.0.1 - bug fixes
  14.     940320 - 1.0.2 - more bug fixes
  15.     951215 - 1.3.0 - updated for CW7
  16.     960704 - 1.3.1 - updated for CW9
  17.     970815 - 1.3.2 - updated for CW Pro 1
  18.  
  19. ---------------------------------------------------------------------- */
  20.  
  21. #include <Types.h>
  22. #include <Memory.h>
  23. #include <Quickdraw.h>
  24. #include <Fonts.h>
  25. #include <ToolUtils.h>
  26. #include <Icons.h>
  27. #include <Controls.h>
  28. #include <Gestalt.h>
  29.  
  30. /* ----------------------------------------------------------------------
  31. prototypes
  32. ---------------------------------------------------------------------- */
  33. pascal long main(short, ControlHandle, short, long);
  34. void drawIt(ControlHandle, short);
  35.  
  36.  
  37. /* ----------------------------------------------------------------------
  38. main
  39. ---------------------------------------------------------------------- */
  40. pascal long main(short variation, ControlHandle theControl, short message, long param)
  41. {
  42.     long    returnValue = 0L;
  43.     char    state = HGetState((Handle)theControl);
  44.     Str255    copyright = "\pCopyright © 1993-1996 Celestin Company, Inc.";
  45.  
  46.     switch(message)
  47.     {
  48.         case drawCntl:
  49.             drawIt(theControl,variation);
  50.         case testCntl:
  51.             break;
  52.         case calcCRgns:
  53.             break;
  54.           case initCntl:
  55.               break;
  56.         case dispCntl:
  57.             break;
  58.         case posCntl:
  59.             break;
  60.         case thumbCntl:
  61.             break;
  62.         case dragCntl:
  63.             break;
  64.         case autoTrack:
  65.             break;
  66.         case calcCntlRgn:
  67.             break;
  68.         case calcThumbRgn:
  69.             break;
  70.         default:
  71.             break;
  72.     }
  73.  
  74.     HSetState((Handle)theControl,state);
  75.  
  76.     return(returnValue);                /* tell them what happened */
  77. }
  78.  
  79.  
  80. /* ----------------------------------------------------------------------
  81. drawIt - here is where we actually draw the control
  82. ---------------------------------------------------------------------- */
  83. void drawIt(ControlHandle control, short variation)
  84.  
  85. {
  86.     Rect             myRect;
  87.     PenState        oldPenState;
  88.     int                myValue = GetCtlValue(control),
  89.                     myMax = GetCtlMax(control),
  90.                     myMin = GetCtlMin(control),
  91.                     myColor,
  92.                     width = 0,
  93.                     range = 100;
  94.  
  95.     if (!(*control)->contrlVis)                /* if not visible, do nothing */
  96.         return;
  97.  
  98.     GetPenState(&oldPenState);                /* save off current environment */
  99.  
  100.     myRect = (*control)->contrlRect;        /* define our control rect */
  101.     
  102.     PenNormal();                            /* make pen normal */
  103.     
  104.     FrameRect(&myRect);                        /* draw border around the control */
  105.     InsetRect(&myRect,1,1);
  106.  
  107.     ForeColor(whiteColor);
  108.     BackColor(whiteColor);
  109.     PaintRect(&myRect);
  110.  
  111.     width = myRect.right - myRect.left;        /* width in pixels of the control */
  112.     range = myMax - myMin;
  113.     
  114.     if (range < 10) range = 10;                /* to deal with screwy ranges */
  115.     
  116.     myRect.right = myRect.left + (myValue * width) / range;
  117.     
  118.     switch (GetCRefCon(control))
  119.     {
  120.         case 1:
  121.             myColor = redColor;
  122.             break;
  123.         case 2:
  124.             myColor = greenColor;
  125.             break;
  126.         case 3:
  127.             myColor = blueColor;
  128.             break;
  129.         case 4:
  130.             myColor = cyanColor;
  131.             break;
  132.         case 5:
  133.             myColor = magentaColor;
  134.             break;
  135.         case 6:
  136.             myColor = yellowColor;
  137.             break;
  138.         case 7:
  139.             myColor = whiteColor;
  140.             break;
  141.         default:
  142.             myColor = blackColor;
  143.             break;
  144.     }
  145.     
  146.     ForeColor(myColor);
  147.     BackColor(myColor);
  148.     PaintRect(&myRect);
  149.  
  150.     ForeColor(blackColor);
  151.     BackColor(whiteColor);
  152.     SetPenState(&oldPenState);                /* restore the original environment */
  153.     
  154.     return;                                    /* we are done drawing */
  155. }
  156.